import { createRouter, createWebHistory } from 'vue-router'
import User from '../views/User.vue'
import UserProfile from '@/views/UserProfile.vue'
import UserPost from '@/views/UserPost.vue'
import UserHome from '@/views/UserHome.vue'

const routes = [
  {
    path: '/user/:id',
    component: User,
    name: 'user-parent',
    children: [
      {
        // 如果将导航到/user/:id而不显示嵌套路由，使用命名路由导航，但重新加载页面将始终显示嵌套的子路由
        path: '',
        name: 'user',
        component: UserHome
      },
      {
        path: 'profile',
        component: UserProfile
      },
      {
        path: 'post',
        component: UserPost
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

// await router.push({name: 'user-parent', params: {id: 145}})

export default router
